<?php 
//ini_set("display_errors",1);
my_component_load('testing' , false);
my_component_load('paging' , false); 
my_component_load('xl_builder' , false);  
my_component_load('list_kalender' , false);   
my_component_load('jadwal_wk_karyawan' );
$task = isset($_GET['task']) ? $_GET['task'] : "";  
$tanggal = isset($_GET['tanggal']) ? $_GET['tanggal'] : "";  
$field = isset($_GET['field']) ? $_GET['field'] : "";  
$value = isset($_GET['value']) ? $_GET['value'] : "";  
$id = isset( $_GET['id'] ) ? $_GET['id']:  0;
$kid = isset( $_GET['kid'] ) ? $_GET['kid']:  0;
$periode_id = isset( $_GET['periode_id'] ) ? $_GET['periode_id']:   get_periode_absen();;
$karyawan_id = isset( $_GET['karyawan_id'] ) ? $_GET['karyawan_id']:  0;
$kelompok_shift_id = isset( $_GET['kelompok_shift_id'] ) ? $_GET['kelompok_shift_id']:  0;

$sc_status_absen_id=isset($_GET['sc_status_absen_id']) ? $_GET['sc_status_absen_id'] : 0;  
$sc_kelompok_shift_id=isset($_GET['sc_kelompok_shift_id']) ? $_GET['sc_kelompok_shift_id'] : 0;  

$modulname = "Personalia _BN_ Waktu Kerja _BN_ Jadwal Kerja _BN_ Schedule";

load_facebox_script();
if($_SERVER['REQUEST_METHOD'] == "POST"){
	if($task == 'upload_schedule_page'){
		upload_exception();
		generate_my_web("Uploaded!!!", $pagename ,"plain.php");
		exit;
	}else{
		submit_ubah_jadwal_wk($kid);
		generate_my_web("Updated!!!", $pagename ,"plain.php");
		exit;
	}
}else{
	if($task == 'update_schedule'){ 
		list($yy,$mm,$day) = explode( '-',$tanggal);
	
		$s = get_karyawan_jadwal($day , 	$karyawan_id, $tanggal );
		$datas = array(
				'karyawan_id'=>my_type_data_str($karyawan_id),
				'tgl_index'=>my_type_data_str($day),
				'old_schedule'=>my_type_data_str($s['kode']),
			);
		my_insert_record( 'a_temp_revisi_schedule', $datas); 
		//print("UPDATE a_temp_jadwal_karyawan SET h{$day} = '{$value}' WHERE karyawan_id = {$karyawan_id} ");exit;
		my_query("UPDATE a_temp_jadwal_karyawan SET h{$day} = '{$value}' WHERE karyawan_id = {$karyawan_id} ");
		my_direct($_SERVER['HTTP_REFERER']);
	}elseif($task == 'update'){ 
		update_jadwal( $tanggal , $field , $value, $karyawan_id );
		my_direct($_SERVER['HTTP_REFERER']);
	}elseif($task == 'edit_wk'){
		facebox_page( 'index.php?com='.$_GET['com'].'&task=edit_wk_page&kid='.$kid, "Setting waktu kerja",170);
		
	}elseif($task == 'upload_schedule_page'){ 
		$content = upload_jadwal(); 
		generate_my_web($content, $pagename ,"plain.php");
		exit;
	}elseif($task == 'upload_schedule'){ 
		$periode_data = my_get_data_by_id('pr_periode','periode_id',$periode_id);
		facebox_page( 'index.php?com='.$_GET['com'].'&task=upload_schedule_page', "Upload jadwal kerja periode ".$periode_data['dari']." s/d ". $periode_data['sampai'] ,170);
	}elseif($task == 'edit_wk_page'){ 
		$content =form_set_waktu($kid);//form_spl_create($id); 
		generate_my_web($content, $pagename ,"plain.php");
		exit;

	}elseif($task == 'excel_data'){
		$periode = my_get_data_by_id('pr_periode','periode_id',$periode_id);
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment;filename=jadwal_karyawan_".date('d-m-Y',strtotime($periode['dari']))."_".date('d-m-Y',strtotime($periode['sampai']))."_".rand(1000,9999) .".xls");
		echo excel_data_karyawan_schedule();
		//echo excel_jadwal_karyawan();
		exit;

	}elseif($task == 'list_detail'){
		$pagename =$modulname." _BN_ Detail";
		$content =  detail_schedule_karyawan($karyawan_id);
	}else{	
		$pagename = $modulname;
		$content = list_karyawan_schedule() ;	
		//$content = list_karyawan_by_periode_id() ;	
	}
}
generate_my_web($content, $pagename );